SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[SP_TCMOVI_BANC_Q11]                        
/*-------------------------------------------------------*/                        
/*---Empresa               OFISIS S.A.                --*/                        
/*---Cliente               CELIMA                     --*/                        
/*---Sistema               Tesoreria                  --*/                        
/*---M¢dulo                Empresa                    --*/                        
/*---Programa              FLUJO DE CAJA REAL SEMANAL (REPORTE)      --*/                        
/*---Script                SP_TCMOVI_BANC_Q03.sql     --*/                        
/*---Nombre SP             SP_TCMOVI_BANC_Q03         --*/                        
/*---Desarrollado por      Reynaldo Menacho Luyo      --*/                        
/*---Fecha Creaci¢n        25/09/2001                 --*/                        
/*---Base Datos            SQL SERVER        --*/                        
/*---Versi¢n               2000                       --*/                        
/*---Invoca a SP                                      --*/                        
/*-------------------------------------------------------*/                        
                        
/*-------------------------------------------------------*/                        
/*---Modificado 1 por           --*/                        
/*---Fecha Modificaci¢n         --*/                         
/*---Detalle Modificaci¢n       --*/                        
/*-------------------------------------------------------*/                        
                        
/*-------------------------------------------------------*/                        
/*---Drop Proc SP_TCMOVI_BANC_Q03                      --*/                        
/*---Grant all on SP_TCMOVI_BANC_Q03 to public         --*/                         
/*---SP_TCMOVI_BANC_Q03 '01', 'DOL', 10, 2001, 11, 2001  --*/                        
/*-------------------------------------------------------*/                        
                        
--EXEC UL_TCMOVI_BANC_Q11 '01', 'WHERE 1 = 1', '', 'U', 'SOL', '2007/01/01', '2007/06/23'               
                      
@ISCO_EMPR Varchar(2),                          
@ISCA_WHER_0001 Varchar(256),                            
@ISCA_WHER_0002 Varchar(256),                       
@ISTI_PRES TD_VC_001,                           
@ISCO_MONE TD_VC_003,                            
@IDFE_OPER_INIC TD_DT_001,                            
@IDFE_OPER_FINA TD_DT_001                
/*,                        
@INNU_MESE_FINA TD_IN_001,                        
@INNU_ANIO_FINA TD_IN_001  */                      
As                        
CREATE TABLE #TWFLUJ_CAJA_Q11_1                        
 ( CO_EMPR      varchar(3) NULL,     
   DE_EMPR      varchar(100) NULL,    
   IM_SALD_FLUJ_PROY numeric(16,4) DEFAULT 0,      
   IM_SALD_FLUJ_EJEC numeric(16,4) DEFAULT 0,                       
   CO_ARUB varchar(3) NULL ,      
   DE_ARUB varchar(100) NULL ,                     
   CO_RUBR varchar(3) NULL ,      
   DE_RUBR varchar(100) NULL ,                      
   CO_SUBR varchar(3) NULL ,       
   DE_SUBR varchar(100) NULL ,                    
   IM_SE01_PROY numeric(16,4) DEFAULT 0,                        
   IM_SE02_PROY numeric(16,4) DEFAULT 0,                        
   IM_SE03_PROY numeric(16,4) DEFAULT 0,                        
   IM_SE04_PROY numeric(16,4) DEFAULT 0,                        
   IM_SE05_PROY numeric(16,4) DEFAULT 0,                        
   IM_SE06_PROY numeric(16,4) DEFAULT 0,                        
   IM_SE07_PROY numeric(16,4) DEFAULT 0,                        
   IM_SE08_PROY numeric(16,4) DEFAULT 0,                        
   IM_SE09_PROY numeric(16,4) DEFAULT 0,                        
   IM_SE10_PROY numeric(16,4) DEFAULT 0,                        
   IM_SE11_PROY numeric(16,4) DEFAULT 0,                      
   IM_SE12_PROY numeric(16,4) DEFAULT 0,       
   IM_SE01_EJEC numeric(16,4) DEFAULT 0,                        
   IM_SE02_EJEC numeric(16,4) DEFAULT 0,                        
   IM_SE03_EJEC numeric(16,4) DEFAULT 0,                        
   IM_SE04_EJEC numeric(16,4) DEFAULT 0,                        
   IM_SE05_EJEC numeric(16,4) DEFAULT 0,                        
   IM_SE06_EJEC numeric(16,4) DEFAULT 0,                        
   IM_SE07_EJEC numeric(16,4) DEFAULT 0,                        
   IM_SE08_EJEC numeric(16,4) DEFAULT 0,                        
   IM_SE09_EJEC numeric(16,4) DEFAULT 0,                        
   IM_SE10_EJEC numeric(16,4) DEFAULT 0,                        
   IM_SE11_EJEC numeric(16,4) DEFAULT 0,                        
   IM_SE12_EJEC numeric(16,4) DEFAULT 0,                                      
   CO_BANC varchar(3) NULL ,                        
   NU_CNTA_BANC varchar(20) NULL ,                        
   DE_CNTA_BANC varchar(100) NULL ,                        
   IM_SALD_INIC numeric(16,4) DEFAULT 0,                      
   TI_DETA_EMPR  varchar(1) NULL ,                      
   TI_DETA_BANC  varchar(1) NULL )                        
                    
                        
DECLARE                        
                        
@VNNU_MESE  TD_IN_001,                        
@VNNU_ANIO  TD_IN_001,                        
@VSNU_MESE  TD_VC_002,                        
@VSNU_ANIO  VARCHAR(4),                        
@VNNU_CONT_MESE TD_IN_001,                        
@VSDE_SELE VARCHAR(6000),                        
@VSCO_EMPR VARCHAR (50),                        
@VSDE_CAMP VARCHAR(7) ,                    
@VSCO_MONE_NACI TD_VC_003,                    
@VSCO_MONE_EXTR TD_VC_003,                  
@VNNU_FACT  NUMERIC(16,4),          
@VNFA_CAMB_MENS  NUMERIC(15,6)                        
                        
  
                 
EXECUTE SP_TCMOVI_BANC_PROY_Q11 @ISCO_EMPR, @ISCA_WHER_0001, @ISCA_WHER_0002, @ISTI_PRES, @ISCO_MONE, @IDFE_OPER_INIC, 
@IDFE_OPER_FINA  
  
EXECUTE SP_TCMOVI_BANC_EJEC_Q11 @ISCO_EMPR, @ISCA_WHER_0001, @ISCA_WHER_0002, @ISTI_PRES, @ISCO_MONE, @IDFE_OPER_INIC, 
@IDFE_OPER_FINA  
                   
     
IF @ISTI_PRES = 'M'                    
 BEGIN  
  
 SELECT T1.CO_EMPR, MAX(T1.DE_EMPR), CONVERT(INT, SUM(T1.IM_SALD_FLUJ_PROY)), CONVERT(INT, SUM(T1.IM_SALD_FLUJ_EJEC)), 
T1.CO_ARUB, MAX(T1.DE_ARUB), T1.CO_RUBR, MAX(T1.DE_RUBR), T1.CO_SUBR, MAX(T1.DE_SUBR),                       
 CONVERT (INT, SUM(ISNULL(T1.IM_SE01_PROY,0))), CONVERT (INT, SUM(ISNULL(T1.IM_SE01_EJEC,0))), CONVERT (INT, 
SUM(ISNULL(T1.IM_SE02_PROY ,0))), CONVERT (INT, SUM(ISNULL(T1.IM_SE02_EJEC ,0))),  
        CONVERT (INT, SUM(ISNULL(T1.IM_SE03_PROY,0))), CONVERT (INT, SUM(ISNULL(T1.IM_SE03_EJEC,0))), CONVERT (INT, 
SUM(ISNULL(T1.IM_SE04_PROY ,0))), CONVERT (INT, SUM(ISNULL(T1.IM_SE04_EJEC ,0))),   
 CONVERT (INT, SUM(ISNULL(T1.IM_SE05_PROY,0))), CONVERT (INT, SUM(ISNULL(T1.IM_SE05_EJEC,0))), CONVERT (INT, 
SUM(ISNULL(T1.IM_SE06_PROY ,0))), CONVERT (INT, SUM(ISNULL(T1.IM_SE06_EJEC ,0))),  
        CONVERT (INT, SUM(ISNULL(T1.IM_SE07_PROY,0))), CONVERT (INT, SUM(ISNULL(T1.IM_SE07_EJEC,0))), CONVERT (INT, 
SUM(ISNULL(T1.IM_SE08_PROY ,0))), CONVERT (INT, SUM(ISNULL(T1.IM_SE08_EJEC ,0))),   
 CONVERT (INT, SUM(ISNULL(T1.IM_SE09_PROY,0))), CONVERT (INT, SUM(ISNULL(T1.IM_SE09_EJEC,0))), CONVERT (INT, 
SUM(ISNULL(T1.IM_SE10_PROY ,0))), CONVERT (INT, SUM(ISNULL(T1.IM_SE10_EJEC ,0))),  
        CONVERT (INT, SUM(ISNULL(T1.IM_SE11_PROY,0))), CONVERT (INT, SUM(ISNULL(T1.IM_SE11_EJEC,0))), CONVERT (INT, 
SUM(ISNULL(T1.IM_SE12_PROY ,0))), CONVERT (INT, SUM(ISNULL(T1.IM_SE12_EJEC,0))),  
        T1.CO_BANC, T1.NU_CNTA_BANC, MAX(T1.DE_CNTA_BANC), MAX(T1.TI_DETA_EMPR), MAX(T1.TI_DETA_BANC)                      
 FROM #TWFLUJ_CAJA_Q11_1 T1                       
 GROUP BY T1.CO_EMPR, T1.CO_ARUB, T1.CO_RUBR, T1.CO_SUBR, T1.CO_BANC, T1.NU_CNTA_BANC            
  
 END  
ELSE  
 BEGIN                    
 SELECT T1.CO_EMPR, MAX(T1.DE_EMPR), SUM(T1.IM_SALD_FLUJ_PROY), SUM(T1.IM_SALD_FLUJ_EJEC),T1.CO_ARUB, MAX(T1.DE_ARUB), 
T1.CO_RUBR, MAX(T1.DE_RUBR), T1.CO_SUBR, MAX(T1.DE_SUBR),                       
 SUM(ISNULL(T1.IM_SE01_PROY,0)), SUM(ISNULL(T1.IM_SE01_EJEC,0)), SUM(ISNULL(T1.IM_SE02_PROY ,0)), SUM(ISNULL(T1.IM_SE02_EJEC 
,0)),  
 SUM(ISNULL(T1.IM_SE03_PROY,0)), SUM(ISNULL(T1.IM_SE03_EJEC,0)), SUM(ISNULL(T1.IM_SE04_PROY ,0)), SUM(ISNULL(T1.IM_SE04_EJEC 
,0)),  
 SUM(ISNULL(T1.IM_SE05_PROY,0)), SUM(ISNULL(T1.IM_SE05_EJEC,0)), SUM(ISNULL(T1.IM_SE06_PROY ,0)), SUM(ISNULL(T1.IM_SE06_EJEC 
,0)),   
 SUM(ISNULL(T1.IM_SE07_PROY,0)), SUM(ISNULL(T1.IM_SE07_EJEC,0)), SUM(ISNULL(T1.IM_SE08_PROY ,0)), SUM(ISNULL(T1.IM_SE08_EJEC 
,0)),  
 SUM(ISNULL(T1.IM_SE09_PROY,0)), SUM(ISNULL(T1.IM_SE09_EJEC,0)), SUM(ISNULL(T1.IM_SE10_PROY ,0)), SUM(ISNULL(T1.IM_SE10_EJEC 
,0)),                  
 SUM(ISNULL(T1.IM_SE11_PROY,0)), SUM(ISNULL(T1.IM_SE11_EJEC,0)), SUM(ISNULL(T1.IM_SE12_PROY ,0)), SUM(ISNULL(T1.IM_SE12_EJEC 
,0)),   
 T1.CO_BANC, T1.NU_CNTA_BANC, MAX(T1.DE_CNTA_BANC), MAX(T1.TI_DETA_EMPR), MAX(T1.TI_DETA_BANC)                      
 FROM #TWFLUJ_CAJA_Q11_1 T1                            
 GROUP BY T1.CO_EMPR, T1.CO_ARUB, T1.CO_RUBR, T1.CO_SUBR, T1.CO_BANC, T1.NU_CNTA_BANC            
 END  
  
                        
RETURN                  
                        
/********************************* FIN ***********************************/


GO
